/***************************************************************************
 * The Open Armory API is a project to retrieve World of Warcraft(R) 
 * related XML data from The Armory.
 * 
 * The data retrieved via the Open Armory API from The Armory is 
 * proprietary to Blizzard Entertainment, Inc(R).
 * *************************************************************************
 * Copyright (C) 2009 - 2010 Tedla M.B. Brandsema
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************************/
package net.openarmory.core.domain.validation;

/**
 * The Class <b>Realm</b>, a JavaBean representation of a single World of
 * Warcraft realm.
 */
public final class Realm {

	private static final int SERVER_COLUMN = 0;
	private static final int TIMEZONE_COLUMN = 1;
	private static final int SERVER_TYPE_COLUMN = 2;
	private static final int HORDE_POPULATION_COLUMN = 3;
	private static final int ALLIANCE_POPULATION_COLUMN = 4;

	/** The server. */
	private String server;

	/** The zone. */
	private String zone;

	/** The timezone. */
	private String timezone;

	/** The server type. */
	private String serverType;

	/** The horde population. */
	private int hordePopulation;

	/** The alliance population. */
	private int alliancePopulation;

	/**
	 * Gets the server.
	 * 
	 * @return the server
	 */
	public String getServer() {
		return this.server;
	}

	/**
	 * Gets the zone.
	 * 
	 * @return the zone
	 */
	public String getZone() {
		return this.zone;
	}

	/**
	 * Gets the timezone.
	 * 
	 * @return the timezone
	 */
	public String getTimezone() {
		return this.timezone;
	}

	/**
	 * Gets the server type.
	 * 
	 * @return the server type
	 */
	public String getServerType() {
		return this.serverType;
	}

	/**
	 * Gets the horde population.
	 * 
	 * @return the horde population
	 */
	public int getHordePopulation() {
		return this.hordePopulation;
	}

	/**
	 * Gets the alliance population.
	 * 
	 * @return the alliance population
	 */
	public int getAlliancePopulation() {
		return this.alliancePopulation;
	}

	/**
	 * Instantiates a new realm.
	 * 
	 * @param csvLine
	 *            the csv line
	 */
	public Realm(final String[] csvLine) {
		extractRealmValues(csvLine);
	}

	/**
	 * Extracts realm values from a single line from the csv file containing
	 * real status.
	 * 
	 * @param csvLine
	 *            the csv line
	 */
	private void extractRealmValues(final String[] csvLine) {
		final String[] csvLineCopy = csvLine;
		for (int i = 0; i < csvLineCopy.length; i++) {
			switch (i) {
			case SERVER_COLUMN:
				setServerAndZone(csvLineCopy[i]);
				break;
			case TIMEZONE_COLUMN:
				this.timezone = csvLineCopy[i];
				break;
			case SERVER_TYPE_COLUMN:
				this.serverType = csvLineCopy[i];
				break;
			case HORDE_POPULATION_COLUMN:
				this.hordePopulation = Integer.parseInt(csvLineCopy[i]);
				break;
			case ALLIANCE_POPULATION_COLUMN:
				this.alliancePopulation = Integer.parseInt(csvLineCopy[i]);
				break;
			default:
				break;
			}
		}
	}

	/**
	 * Sets the server and zone members.
	 * 
	 * @param server
	 *            the new server and zone
	 */
	private void setServerAndZone(final String server) {
		if (server.startsWith("EU-", 0)) {
			this.server = server.replace("EU-", "");
			this.zone = "EU";
		} else {
			this.server = server;
			this.zone = "US";
		}
	}
}
